﻿

GY.Bill.Bank = {
    //获取热门银行
    GetHotBank: function () {
        var $divHot = $("#div_bank_hot");
        $.ajax({
            type: "Post",
            url: $divHot.attr("data-url"),
            data: null,
            dataType: "json",
            success: function (result) {
                var items = [];
                if (result.code == 1) {
                    for (var i = 0; i < result.data.length; i++) {
                        items.push("<a href=\"javascript:;\" data-val=\"" + result.data[i]["Id"] + "\" class=\"fl\">"
                        + result.data[i]["BankName"] + "</a>");
                    }
                }
                $divHot.html(items.join(""));
            }
        });
    },
    //搜索银行
    GetBankByKey: function (key) {
        var $divList = $("#div_bank_result_list");
        $.ajax({
            type: "Post",
            url: $divList.attr("data-url"),
            data: { key: key },
            dataType: "json",
            success: function (result) {
                if (result.code == 1) {
                    var items = [];
                    if (result.code == 1) {
                        for (var i = 0; i < result.data.length; i++) {
                            items.push("<a href=\"javascript:;\" data-val=\"" + result.data[i]["Id"] + "\" class=\"fl\">"
                            + result.data[i]["BankName"] + "</a>");
                        }
                    }
                    $divList.html(items.join(""));
                }
            }
        });
    }
};
(function () {
    $(function () {
        //选择银行
        $("#txtBank").focus(function () {
            $("#div_bank_search").show();
            $("#divMain").hide();

            GY.Bill.Bank.GetHotBank();
        });

        $("#btn_bank_goback").click(function () {
            $("#divMain").show();
            $("#div_bank_search").hide();
        });

        //搜索银行
        $("#btnSearch").on("tap", function () {
            var key = $("#txtBankKey").val();

            if (key == "") {
                return;
            }

            $("#div_bank_result").show();
            $("#div_bank_search").hide();

            GY.Bill.Bank.GetBankByKey(key);
        });

        $("#btnSearchResult").on("tap", function () {
            var key = $("#txtBankResultKey").val();

            if (key == "") {
                return;
            }

            $("#div_bank_result").show();
            $("#div_bank_search").hide();
            GY.Bill.Bank.GetBankByKey(key);
        });

        $("#btn_bankResult_goback").click(function () {
            $("#div_bank_search").show();
            $("#div_bank_result").hide();
        });

        //点击银行赋值
        $(".banklist").on("tap", "a", function () {
            $("#div_bank_search").hide();
            $("#div_bank_result").hide();
            $("#divMain").show();
            var $this = $(this);
            $("#txtBank").val($this.text());
            $("#txtBank").attr("data-val", $this.attr("data-val"));
        });
    });
})();

